package com.xbongbong.formula.qlexpress.operator.text;

import com.ql.util.express.Operator;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.util.MathUtil;
import com.xbongbong.pro.enums.ErrorCodeEnum;
import com.xbongbong.pro.enums.errorcodes.ProErrorCodeEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author: wufeng
 * @date: 2018/7/4 10:29
 * @desrcption:  将数字舍入到指定的小数位数，以十进制数格式对该数进行格式设置，并以文本形式返回结果。
 */
public class OperatorFixed extends Operator {

    private static final Logger LOGGER = LoggerFactory.getLogger(OperatorFixed.class);

    public OperatorFixed(String name){
        this.name = name;
    }

    public OperatorFixed(String aAliasName, String aName, String errorInfo){
        this.aliasName = aAliasName;
        this.name = aName;
        this.errorInfo = errorInfo;
    }

    @Override
    public Object executeInner(Object[] list) throws Exception {
        try {
            return MathUtil.round(((Number) list[0]).doubleValue(), ((Number) list[1]).intValue());
        } catch (Exception e) {
            LOGGER.error("OperatorFixed公式解析计算错误：", e);
            throw new XbbException(ProErrorCodeEnum.API_ERROR_260018);
        }

    }
}
